package lium.lbs.lbsim.utils;

import android.content.Context;
import android.text.TextUtils;
import com.lmlibrary.Constants;
import com.lmlibrary.event.LoginOutEvent;
import org.greenrobot.eventbus.EventBus;

/**
 * Description:
 */
public class UserUtils {
    /**
     * 判断用户是否登录
     *
     * @return
     */
    public static boolean isLogin() {
        String memberId = (String) SpUtils.getInstance().get(Constants.memberId, "");
        if (!TextUtils.isEmpty(memberId)) {
            return true;
        }
        return false;
    }

    public static boolean forLogin(Context context) {
        if (isLogin()) {
            return true;
        }
       // Intent intent = new Intent(context, LoginByCodeActivity.class);
        // context.startActivity(intent);
        return false;
    }

    /**
     * 登录成功，存储账户信息
     *
     * @param memberId
     */
    public static void login(String memberId) {
        if (memberId == null) {
            return;
        }
        SpUtils.getInstance().put(Constants.memberId, memberId);
    }
    /**
     * 获取个人信息存储
     */
    public static void setUserData(String uniqueCode,String nickName,String headImage,String phone) {
        SpUtils.getInstance().put(Constants.uniqueCode, uniqueCode);
        SpUtils.getInstance().put(Constants.nickName, nickName);
        SpUtils.getInstance().put(Constants.headImage, headImage);
        SpUtils.getInstance().put(Constants.phone, phone);


    }
    /**
     * 退出账号登录
     */
    public static void loginOut(Boolean isNeedBroad) {
        EventBus.getDefault().post(new LoginOutEvent());
      //  String user_id = (String) SpUtils.getInstance().get(Constants.token, "");
        SpUtils.getInstance().remove(Constants.memberId);
        SpUtils.getInstance().remove(Constants.uniqueCode);
        SpUtils.getInstance().remove(Constants.nickName);
        SpUtils.getInstance().remove(Constants.headImage);
        SpUtils.getInstance().remove(Constants.phone);

        SpUtils.getInstance().remove(Constants.igronVersionNum);
        SpUtils.getInstance().clear();
    }
}
